#! /bin/sh 

#安装插件
if [ ! -f "/root/.jenkins/plugins.zip" ]; then
mkdir -p /root/.jenkins/
\cp -f /usr/local/jenkins/plugins.zip  /root/.jenkins/plugins.zip

yum -y install unzip
cd /root/.jenkins/
unzip plugins.zip

fi

#启动jenkins
chmod +x /usr/local/jenkins/jenkins.sh
/usr/local/jenkins/jenkins.sh start

#开机启动
echo '

/usr/local/jenkins/jenkins.sh start

'>>/etc/rc.d/init.d/autostart.sh

chmod 755 /etc/rc.d/init.d/autostart.sh




#下载maven 和 node
\mv -f /usr/local/jenkins/apache-maven-3.6.3-bin.tar.gz  /usr/local

# 解压maven
cd /usr/local
tar -xzvf apache-maven-3.6.3-bin.tar.gz

sed -i '159i <mirror> \n <id>aliyunmaven</id> \n <mirrorOf>*</mirrorOf> \n <name>阿里云公共仓库</name> \n <url>https://maven.aliyun.com/repository/public</url> \n </mirror>' /usr/local/apache-maven-3.6.3/conf/settings.xml



echo '

export M2_HOME=/usr/local/apache-maven-3.6.3
export PATH=$PATH:${M2_HOME}/bin

export PATH=$PATH:/usr/local/node-v14.9.0-linux-x64/bin

'>>/etc/profile

source /etc/profile

\cp /usr/local/jenkins/node-v14.9.0-linux-x64.tar.gz /usr/local/
cd /usr/local
tar xf node-v14.9.0-linux-x64.tar.gz
#安装 cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org

#设置淘宝镜像
npm config set registry https://registry.npm.taobao.org

#安装git
yum -y install git



# 解压备份文件
cd /usr/local/jenkins/
rm -rf /usr/local/jenkins/FULL*
unzip bak.zip

echo "
#设置 ThinBackup 设置备份目录 /usr/local/jenkins/   Restore 恢复备份
"

/usr/local/jenkins/jenkins.sh stop
